#region Using directives
using System;
using System.Collections;
	
using System.Data ;
using WP.DB;
using WP.MF.DataEntity; 
using WP.Commons;
#endregion

namespace WP.MF.DataAccess
{

	/*
	 * Created by Z
	 * At  Monday, August 01, 2005
	 */

    public class MBranchDAL : IDataAccess
	{
		public MBranchDAL()
		{
		}

        #region Select List
        public string SQLList(int iParameter)
        {
            string strSQL = @"select RecID,branchno,branchdesc from mbranch ORDER BY branchno ";
            return strSQL;
        }
        #endregion

		#region Fields
		public string Fields
		{
			get
			{
                return @"branchno,branchdesc,InvAcctNo,InvProfitNo,Street, City, ProvNo, PostalCode, Fax, Phone,CompanyPhone01,CompanyPhone02,PrtBrnDescAndAddress,AddPullCard,PoOrdno,PurchaseOrderFirstChar,InvAcctNo1,InvProfitNo1,NextOrdNo,SalesOrderFirstChar,NextJobNo";
			}
		}
		#endregion

		#region SelectMBranchForLookUp
		public string SelectMBranchForLookUp()
		{
			return "select BranchNo,BranchDesc,RecID from mbranch";
		}		
		#endregion		

		#region  SelectBranchForList
		/// <summary>
		/// Get BranchnNo and BranchDesc for show Branch info with a dropdownlist control
		/// </summary>
		/// <param name="dBAccess"></param>
		/// <returns></returns>
		public DataView SelectBranchForList(DBAccess dBAccess)
		{
			string strSql="";
			
			strSql="SELECT BranchNo,(BranchNo+' - '+rTrim(BranchDesc)) as BranchDesc FROM mBranch Order by BranchNo";

			return dBAccess.GetDataSet(strSql).Tables[0].DefaultView;
		}
		#endregion
		

		#region Select MBranch by RecId
		public MBranchDEL SelectMBranchByKey(DBAccess dBAccess, string strRecId)
		{
			MBranchDEL BranchDEL=new MBranchDEL();
			string strSql=string.Empty;


			strSql="SELECT "+Fields+",RecId,RecStamp FROM MBranch ";
			
			if(strRecId !="" && int.Parse(strRecId)>=0)
			{
				strSql+=" WHERE RecId="+strRecId;
			}

			dBAccess.GetDataSet(strSql,MBranchDEL.TABLENAME_MBRANCH,BranchDEL);

			return BranchDEL;
		}
		#endregion

		#region Insert table 
		public void InsertMBranch(DBAccess dBAccess,MBranchDEL BranchDEL)
		{
			string strSql=string.Empty;

			DataRow dr=BranchDEL.Tables[MBranchDEL.TABLENAME_MBRANCH].Rows[0];
			
			strSql=BaseFunctions.GenerateSqlForDataAccess(Fields,MBranchDEL.TABLENAME_MBRANCH,dr,FormStatus.AddNew);

			dr["RecId"]=dBAccess.GetIntValue(strSql);
		}
		#endregion

		#region Update MBranch
		public void UpdateMBranch(DBAccess dBAccess,MBranchDEL BranchDEL)
		{
			string strSql=string.Empty;
			DataRow dr=BranchDEL.Tables[0].Rows[0];

			strSql=BaseFunctions.GenerateSqlForDataAccess(Fields,MBranchDEL.TABLENAME_MBRANCH,dr,FormStatus.Update);
			
			dr[MBranchDEL.RECSTAMP]=dBAccess.GetObjectValue(strSql);
		}
		#endregion

		#region Delete MBranch by Key
		public void DeleteMBranch(DBAccess dBAccess,string strRecId)
		{
			string strSql="";

			strSql="delete from MBranch WHERE RecId = " + strRecId;

			dBAccess.ExecuteSql(strSql);
		}
		#endregion
	}

}